package uit.shoeshop.model;

import uit.shoeshop.dto.CategoryDTO;
import uit.shoeshop.dto.ProductDTO;
import uit.shoeshop.dao.CategoryDAO;
import uit.shoeshop.dao.ProductDAO;

import java.sql.SQLException;
import java.util.ArrayList;

public class CategoryModel {
	public CategoryModel(){
		
	}
	
	public ArrayList<ProductDTO> getAllProductbyCateID(int cid,int page) throws SQLException{
		ArrayList<ProductDTO> product = new ArrayList<ProductDTO>();

		ProductDAO tblProduct = new ProductDAO();
		/*
		 * Lay tat ca cac product cua category
		 */
		product = tblProduct.getProductbyCateID(cid, page);
		
		tblProduct = null;
		return product;
	}

	public String getTitleCategory(int cid) throws SQLException{
		CategoryDTO category = new CategoryDTO();

		CategoryDAO tblCategory = new CategoryDAO();
		/*
		 * Lay tieu de category
		 */
		category = tblCategory.getCategorybyID(cid, 1);
		
		tblCategory = null;
		return category.getTitle();
	}
		
	public Integer countTotalProduct(int cid) throws SQLException{
		Integer result = 0;

		ProductDAO tblProduct = new ProductDAO();
		/*
		 * Dem tong san pham trong category
		 */
		result = tblProduct.countProductbyCateID(cid);
		
		tblProduct = null;
		return result;
	}
	
	public int delCategory(int sId) throws SQLException{
		int result = 1;
		CategoryDAO tblCategory = new CategoryDAO();
		result = tblCategory.delCategory(sId);
		return result;
	}
	
	public int activeCategory(int sId) throws SQLException{
		int result = 1;
		CategoryDAO tblCategory = new CategoryDAO();
		result = tblCategory.activeCategory(sId);
		return result;
	}
	
	public int editCategory(int sId,String title,int parent_id,int enabled) throws SQLException{
		int result = 1;
		CategoryDAO tblCategory = new CategoryDAO();
		result = tblCategory.editCategory(sId,title,parent_id,enabled);
		return result;
	}
	
	public int addCategory(String title,int parent_id,int enabled) throws SQLException{
		int result = 1;
		CategoryDAO tblCategory = new CategoryDAO();
		result = tblCategory.addCategory(title,parent_id,enabled);
		return result;
	}
	
	public ArrayList<CategoryDTO> getAllCategory() throws SQLException{
		ArrayList<CategoryDTO> category = new ArrayList<CategoryDTO>();

		CategoryDAO tblCategory = new CategoryDAO();
		/*
		 * Lay tat ca cac product cua category
		 */
		category = tblCategory.getAllCategory();
		
		tblCategory = null;
		return category;
	}
	
	public ArrayList<CategoryDTO> getAllParentCategory() throws SQLException{
		ArrayList<CategoryDTO> category = new ArrayList<CategoryDTO>();

		CategoryDAO tblCategory = new CategoryDAO();
		
		/*
		 * Lay tat ca cac category cha
		 */
		category = tblCategory.getParentCategory();
		
		tblCategory = null;
		return category;
	}
	
	public CategoryDTO getCategorybyID(int cid) throws SQLException{
		CategoryDTO category = new CategoryDTO();

		CategoryDAO tblCategory = new CategoryDAO();
		
		category = tblCategory.getCategorybyID(cid);
		
		tblCategory = null;
		return category;
	}
}
